package com.dxf.bigdata.D05_spark_again

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Distinct {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("app")

    val sc = new SparkContext(sparkConf)


    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4, 1,2,3,4,5))

    //distinct  原理 :  map(x => (x, null)).reduceByKey((x, _) => x, numPartitions).map(_._1)
    val value: RDD[Int] = rdd.distinct()
    val value2: RDD[Int] = rdd.map(x => (x, null)).reduceByKey((x, _) => x).map(_._1)

    value.foreach(println)


    //别忘记
    sc.stop()




  }
}